//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "client\fn_clientExecuteTeleportAI.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_grp","_AIs","_last_used","_can_teleport"];
_AIs = [];
_grp = group player;
_last_used = PGETVAR(QGVAR(LAST_AI_TELEPORT_TIME),-10000);
_can_teleport = true;
if (!isNil "_last_used") then {
	if ((time - _last_used) < 30) exitwith {
		player sideChat Format[localize "STR_MF_TELEPORT_AI_WAIT",ceil(30 - (time - _last_used))];
		_can_teleport = false;
	};
};
if (_can_teleport) then {
	if (_grp != grpNull) then {
		{
			if (alive _x && !isplayer _x && (_x distance player) <= 5) then {
				_AIs set [ count _AIs, _x];
			};
		} foreach units _grp;
	};
	if (count _AIs > 0) then {
		{
			_x setPos (getPos player);
		} foreach _AIs;
		PSETVAR(QGVAR(LAST_AI_TELEPORT_TIME),time);
	};
};

TRACE("End");
TMFPROFILERSTOP;